package main

import "fmt"

// type switch

func main() {
	// x 是一个接口类型变量，它的静态类型为 interface{}
	// 当给 x 赋值 13，x 接口变量的动态类型就是 int
	var x interface{} = 13

	// x.(type) 只能在 switch 中使用
	switch x.(type) {
	case nil:
		fmt.Println("x is nil")
	case int:
		fmt.Println("the type of x is int")
	case string:
		fmt.Println("the type of x is string")
	case bool:
		fmt.Println("the type of x is bool")
	default:
		fmt.Println("don't support the type")
	}

	switch v := x.(type) {
	case nil:
		fmt.Println("x is nil")
	case int:
		fmt.Println("the type of x is int, value is", v)
	case string:
		fmt.Println("the type of x is string, value is", v)
	case bool:
		fmt.Println("the type of x is bool, value is", v)
	default:
		fmt.Println("don't support the type")
	}
}
